<?php

if(!Session::get('uid')){
	Redirect::index();
}
$pub = new Model('pubs');
$pub->find(array('uid'=>Session::get('uid')));
$user = new Model('user');
$data = $user->field('pagetype')->find(Session::get('uid'));
$agency = get_user_agency();
$userui = new Model('user_agency_userui');
$userui->find(['pid'=>$agency->id]);

// if($userui->ui == 1){
// 	$to='/admin/main';
// }elseif($userui->ui == 2){
// 	$to='/admin/main1';
// }
$to='/admin/main';
if(!$pub->has_id()){
	$pub->uid = Session::get('uid');
	$pub->isval = '0';
	$pub->save();
	Session::set('wid',$pub->id);
	Redirect::to($to);
}else if($pub->isval !='1'){
	Session::set('wid',$pub->id);
	Redirect::to($to);
}else{	
	Session::set('wid',$pub->id);
	Redirect::to($to);
}
